#!/bin/bash

#Directions: Set up a cron job to backup at desired intervals. Google is your friend if you don't know how to do this.

# EDIT HERE
#Set the WORLD_DIR equal to your world dir.
WORLD_DIR="${HOME}/Desktop/SMP/world"
#Number of backups
BACKUPS=10
# STOP EDIT HERE

if [ -d ${WORLD_DIR}.backup${BACKUPS} ]; then
	rm -rf ${WORLD_DIR}.backup${BACKUPS}
fi

#i=`ls -d ${WORLD_DIR}.backup* | wc -l`
i=$BACKUPS
while [ $i -gt 0 ]; do
	j=`expr $i - 1`
	if [ -d ${WORLD_DIR}.backup${j} ]; then
		mv ${WORLD_DIR}.backup${j} ${WORLD_DIR}.backup${i}
	fi
	i=$j
done

cp -r $WORLD_DIR ${WORLD_DIR}.backup1
